<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
table.gridtable {
	font-family: verdana, arial, sans-serif;
	font-size: 11px;
	color: #333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}

table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}

table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}

tr:hover td {
	background: none;
}

tr:hover {
	background-color: none;
}
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}
table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  padding: 8px;
  text-align: left;
}

th {
  background-color: #f2f2f2;
}
#myDiv { 
     top: 0px;
     right: 0;
     background-color: #f1f1f1;
     padding: 10px;
     overflow-y:auto;
   }
   #resultDiv,div1,div2 { 
     top: 20px;
     right: 0;
     background-color: #f1f1f1;
     padding: 10px;
     overflow-y:auto;
   }
</style>
<meta charset="UTF-8">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/grid1.0.js"></script>
</head>
<body style="overflow:auto;">
涨跌幅：<input type="text" id="text1" value="9.9" style="width:50px" placeholder="涨跌幅">到
<input type="text" id="text4" value="20" style="width:50px" placeholder="涨跌幅">
换手率：<input type="text" id="text2" value="5" style="width:50px"  placeholder="换手率">
市总值：<input type="text" id="text3" value="300" style="width:50px"  placeholder="换手率">
<button id="bt0">查询</button> 
<button id="bt1">显示选中</button> 
<button id="bt1_5">换手率排序</button>
<button id="bt2">加载概念</button> 
<button id="bt3">恢复</button>
<button id="bt4">加载评论</button>
<button id="bt5">保存评价</button>
<input type="text" id="sp">
<button id="bt7">保存快照</button>
<input type="text" id="text5" value="" style="width:50px" placeholder="关键字">
<button id="bt8">保存关键字</button>
<hr>
最近<input type="text" style="width:50px" id="day" value="3">天，每日换手率不低于<input type="text" style="width:50px" id="zuixiaohuanshou" value="10">每日涨跌幅不低于<input type="text" style="width:50px" id="zuixiaozhangdiefu" value="0">总涨跌幅不高于<input type="text" style="width:50px" id="zongzhangdiefu" value="10">
<button id="bt9">查询静态高标</button>
<button id="bt10">查询今日动态高标</button>
<button id="bt11">查询静负高标</button>
<hr>
最小换手率大于<input type="text" style="width:50px;" value="4" id="hsl1">
连续<input type="text" style="width:50px;" value="3" id="day1">天依次放大股票  单日涨跌幅不低<input type="text" style="width:50px;" value="0" id="bt13text">
几日类总波动幅度载<input type="text" style="width:50px;" value="-1" id="bo1">-<input type="text" style="width:50px;" value="4" id="bo2">之间
<select id= "select1">
 <option value="0">依次放大</option>
 <option value="1">依次缩小</option>
</select>
<button id="bt13">查询异动股</button>
<hr>

<div id="resultDiv">
	<div id="div1"></div>
	<div id="div2"></div>
</div>
<div id="myDiv"></div>

<script type="text/javascript">


(function(){ 

	$("#bt14").click(function(){
		$('#div1').html("");
		$('#div2').html("");
		$.ajax({
			type : "get",
			url : "${pageContext.request.contextPath}/getMeiTianChao70baifen10dian", 
			data:{},
			dataType:'text',
			success : function(msg) {   
				$("#myDiv").html(msg);
				$("#mytalbe").addClass("gridtable");  
				loadUrl();
				 $("#mytalbe td[name=huanshoulv0]").each(function(){
				        var num = parseFloat($(this).text()); 
				        var roundedNum = num.toFixed(2);
				        $(this).text(roundedNum);
				 });
				 $("#mytalbe td[name=beisu]").each(function(){
				        var num = parseFloat($(this).text());
				        
				        var roundedNum = num.toFixed(2);
				        $(this).text(roundedNum);
				 });
			}
		});
	});
	
	$("#bt15").click(function(){
		 $("#mytalbe tr").each(function() {
		        let seventhColValue = parseFloat($(this).find("td:nth-child(7)").text());
		        let thirdColValue = parseFloat($(this).find("td:nth-child(3)").text());
		        if (seventhColValue/thirdColValue  < $("#hsl1_bt14").val()) {
		            $(this).hide();
		        } 
		    });
	});
	
	
	$("#bt13").click(function(){
		 var hsl1 =  $("#hsl1").val(); 
		 var day1 =  $("#day1").val(); 
		 var jiage =  $("#bt13text").val();  
		 var select1 = $("#select1").val();
		 var bo1 = $("#bo1").val();
		 var bo2 = $("#bo2").val();
		 var obj = {};
		 obj.hsl =hsl1;
		 obj.day =day1;
		 obj.jiage = jiage;
		 obj.select =select1; 
		 obj.bo1 =bo1;
		 obj.bo2 =bo2;
		$.ajax({
			type : "get",
			url : "${pageContext.request.contextPath}/getHsldizengDay", 
			data:obj,
			dataType:'text',
			success : function(msg) {   
				$("#myDiv").html(msg);
				$("#mytalbe").addClass("gridtable");  
			 	var tds = $("table tr:first th"); 
				  // 遍历每个td元素
				  
				loadUrl();
			}
		});
		
	});
	$("#bt8").click(function(){
		 $('table td[name=gn]').each(function() {
			    var content = $(this).text();
			    if (!content.includes($("#text5").val())) {
			      $(this).parent().hide();
			    }
			  }); 
	}); 
	function load(){
		 $('#div1').html("");
		 $('#div2').html("");
		$.ajax({
			type : "get",
			url : "${pageContext.request.contextPath}/getStockCT5", 
			data:{date1:$("#date2").val()},
			dataType:'text',
			success : function(msg) {   
				$("#myDiv").html(msg);
				$("#mytalbe").addClass("gridtable");  
				loadUrl();
			}
		});
	}
	
	$("#bt9").click(function(){
		selectgb(1);
	});
	
	$("#bt10").click(function(){
		selectgb(2);
	});
	$("#bt11").click(function(){
		selectgb(3);
	});
	
	$("#bt12").click(function(){
		selectgb(4); 
	});
	
	function selectgb(flag){
		 $('#div1').html("");
		 $('#div2').html("");
		 var  day = $("#day").val();
		 var zuixiaohuanshou =  $("#zuixiaohuanshou").val();
		 var zuixiaozhangdiefu =  $("#zuixiaozhangdiefu").val();
		 var zongzhangdiefu =  $("#zongzhangdiefu").val(); 
		 var chaju1 =  $("#chaju1").val(); 
		 var huanshou1 =  $("#huanshou1").val(); 
		 var danrizhangdiefu = $("#danrizhangdiefu").val(); 
		 var zongzhangdiefu1 = $("#zongzhangdiefu1").val(); 
		$.ajax({
			type : "post",
			url : "${pageContext.request.contextPath}/getzuijin", 
			data:{day:day,zuixiaohuanshou:zuixiaohuanshou,zuixiaozhangdiefu:zuixiaozhangdiefu,zongzhangdiefu:zongzhangdiefu,flag:flag,chaju1:chaju1,huanshou1:huanshou1,danrizhangdiefu:danrizhangdiefu,zongzhangdiefu1:zongzhangdiefu1},
			dataType:'text',
			success : function(msg) {  
				$("#myDiv").html(msg);
				$("#mytalbe").addClass("gridtable");  
				var tds = $("table tr:first th"); 
				  // 遍历每个td元素
				  tds.each(function(){
				    // 检查td的值是否等于'aaa'，如果是，则替换为'bbb' 
				    if($(this).text() == "zhandifu"){
				      $(this).text("当前涨跌幅度");
				    }
				    if($(this).text() == "minh"){
					      $(this).text("三日内最小换手");
					    }
				    if($(this).text() == "sumz"){
					      $(this).text("几日内总涨跌幅");
					    }
				    if($(this).text() == "minz"){
					      $(this).text("几日内最小涨跌幅");
					    }
				  });
				loadUrl();
			}
		}); 
	}
	
	
	$("#bt4").click(function(){ 
		$("table tr:first").append("<th>评价</th>");
		$("#mytalbe").find("tr:not(:first)").each(function() { 
			  var code = $( $(this).children()[2]).attr("code").substring(2);
			  $(this).append("<td name='note1'><textarea style='width:300px;height:100px;' code='"+code+"'></textarea></td>");
		});
		 var thirdColumnContents = [];
		   $('table tr:not(:first)').each(function() {
			  var thirdColumnValue = $(this).find('td:eq(2)').text().substring(2);
			  thirdColumnContents.push(thirdColumnValue);
			}); 
		   var commaSeparatedString = thirdColumnContents.join(",");
		$.ajax({
			type : "post",
			url : "${pageContext.request.contextPath}/getNote1", 
			data:{code:commaSeparatedString},
			dataType:'json',
			success : function(msg) { 
				$("textarea").each(function() {
					  var code = $(this).attr("code");
					  // 根据 code 属性进行相应的赋值操作
					  for(var i=0;i<msg.length;i++){
						  if(code == msg[i].code){
							  $(this).val(msg[i].note1);
							  break;
						  }
					  } 
				});
			}
		});  
		
	});
	$("#bt5").click(function(){
		var listtd = $("td[name=note1]");  
		var arr = [];
		for(var i=0;i<listtd.length;i++){ 
			var obj = {}; 
			if($(listtd[i]).children().val()=="" || $(listtd[i]).children().val().length<=0){
				continue;
			}
			obj.code = $(listtd[i]).children().attr("code");
			obj.note1= $(listtd[i]).children().val(); 
			arr.push(obj);
		}
		console.log(arr.length);
		var all = JSON.stringify(arr);
		$.ajax({
			type : "post",
			url : "${pageContext.request.contextPath}/addpinfen", 
			data:{all:all},
			dataType:'json',
			success : function(msg) {  
				alert("成功"); 
			}
		});   
	});
	  $("#bt7").click(function(){ 
    	var tdlist = $("td[name=code]");
    	var jsonObj= [];
    	if($("#sp").val().length<=0){
    		
    		alert("快照名称不能为空");
    		return;
    	}
    	for(var i=0;i<tdlist.length;i++){
    		console.log(i);
    		var siblings = $(tdlist[i]).siblings();
    		var stock={};
    		stock.code = $(tdlist[i]).text(); 
    		siblings.each(function() {
    		    var attr = $(this).attr("name");
    		   if(attr == 'name'){
    			   stock.name = $(this).text();
    		   } 
    		   if(attr == 'huanshoulv'){
    			   stock.huanshoulv = $(this).text();
    		   }
    		   if(attr == 'zhangdiefu'){
    			   stock.zhangdiefu = $(this).text();
    		   }
    		   if(attr == 'shizhi'){
    			   stock.shizhi = $(this).text();
    		   }
    		   if(attr == 'jiage'){
    			   stock.jiage = $(this).text();
    		   }
    		});
    		console.log(stock);
    		stock.sp = $("#sp").val();
    		jsonObj.push(stock);
    	} 
    	var jsonString = JSON.stringify(jsonObj);
    	console.log(jsonString);
    	$.ajax({
			type : "post",
			url : "${pageContext.request.contextPath}/addstockpcitrue", 
			data:{all:jsonString},
			dataType:'json',
			success : function(msg) {  
				alert("成功"); 
			}
		});   
    });
	function loadUrl(){
		$('table tr').each(function() {
		    var thirdColumn = $(this).find('td[name=code]');
		    var linkText = thirdColumn.text();  
		    thirdColumn.html('<a href=http://quote.eastmoney.com/concept/'+linkText+'.html target="_blank">' + linkText + '</a>');
		 });
	}
	$("#bt1").click(function(){
		$('table tr:not(:first)').each(function() {
			  var value = parseFloat($(this).find('td:nth-child(2)').text());
			  if (value <= parseFloat($("#text1").val()) || value >= parseFloat($("#text4").val())) {
			     $(this).remove();
			  }
			  
			  var value = parseInt($(this).find('td:nth-child(5)').text());
			  if (value < $("#text2").val()) {
			    $(this).remove();
			  }
			  var value = parseInt($(this).find('td:nth-child(6)').text());
			  if (value > $("#text3").val()) {
			    $(this).remove();
			  }
			}); 
	});

	$("#bt2").click(function(){
		   var thirdColumnContents = [];
		   $('table tr:not(:first)').each(function() {
			  var thirdColumnValue = $(this).find('td[name=code]').text().substring(2);
			  thirdColumnContents.push(thirdColumnValue);
			}); 
		   console.log(thirdColumnContents.length);
		   var commaSeparatedString = thirdColumnContents.join(",");
		$.ajax({
			type : "post",
			url : "${pageContext.request.contextPath}/getStockCT5GN", 
			data:{code:commaSeparatedString},
			dataType:'json',
			success : function(msg) { 
				console.log(msg);
				var allarr=[];
				var allarr1=[];
				$("table tr:first").append("<th style='width:200px'>GN</th>");
				$("table tr:first").append("<th style='width:200px'>CP</th>"); 
				$("table tr:first").append("<th style='width:100px'>HY</th>");
				$("table tr:first").append("<th style='width:100px'>JLR</th>");
				//$("table tr:first").append("<th style='width:100px'>CJ15</th>"); 
				  console.log(msg.length);
				 for(var i=0;i<msg.length;i++){
					 var code = msg[i].code; 
					 var gn =msg[i].gn; 
					 var cp =msg[i].cp; 
					 var hy =msg[i].hy; 
					 var jlr =msg[i].jlr; 
					 if($("td[code=sh"+code+"]").length>0){
						 $("td[code=sh"+code+"]").parent().append("<td name='gn'>"+gn+"</td>"); 
						 $("td[code=sh"+code+"]").parent().append("<td name='cp'>"+cp+"</td>");
						 $("td[code=sh"+code+"]").parent().append("<td name='hy'>"+hy+"</td>");
						 $("td[code=sh"+code+"]").parent().append("<td name='jlr'>"+jlr+"</td>"); 
					 }else{
						 $("td[code=sz"+code+"]").parent().append("<td name='gn'>"+gn+"</td>");
						 $("td[code=sz"+code+"]").parent().append("<td name='cp'>"+cp+"</td>");
						 $("td[code=sz"+code+"]").parent().append("<td name='hy'>"+hy+"</td>");
						 $("td[code=sz"+code+"]").parent().append("<td name='jlr'>"+jlr+"</td>"); 
					 }  
				 }
				 
			}
		});  
	});
	
	function loadKey(array){ 
		var count = {};
		$.each(array, function(i, value) {
		    if (value in count) {
		        count[value]++;
		    } else {
		        count[value] = 1;
		    }
		});
		// 将结果转换成可排序的数组
		var sortable = [];
		for (var key in count) {
		    sortable.push([key, count[key]]);
		}

		// 按数量从大到小排序
		sortable.sort(function(a, b) {
		    return b[1] - a[1];
		});

		// 取出前10个结果并生成对应的label，附加出现的数量，设置背景颜色为绿色，间隔为5px
		var top10 = sortable.slice(1, 10);
		var labels = '';
		$.each(top10, function(i, value) {
			 
		    labels += '<label style="background-color: green; margin-right: 5px;">' + value[0] + ' (' + value[1] + ')' + '</label>';
		});
		$('#div1').append(labels+"<hr>");
		lableclick();
	}
	function loadLT(array){ 
		var count = {};
		$.each(array, function(i, value) {
		    if (value in count) {
		        count[value]++;
		    } else {
		        count[value] = 1;
		    }
		});
		// 将结果转换成可排序的数组
		var sortable = [];
		for (var key in count) {
		    sortable.push([key, count[key]]);
		}

		// 按数量从大到小排序
		sortable.sort(function(a, b) {
		    return b[1] - a[1];
		});

		// 取出前10个结果并生成对应的label，附加出现的数量，设置背景颜色为绿色，间隔为5px
		var top10 = sortable.slice(1, 10);
		var labels = '';
		$.each(top10, function(i, value) { 
		    labels += '<label style="background-color: red; margin-right: 5px;margin-top:5px;">' + value[0] + ' (' + value[1] + ')' + '</label>';
		});
		$('#div2').append(labels); 
	} 
	function lableclick(){
		$('#resultDiv').find("label").click(function(){ 
			var keyword = $(this).text().slice(0, -4); 
			filterTableRows(keyword);
		});
	}
	
	
	function filterTableRows(keyword) {
	    $('table tr').show(); // 首先显示所有的表格行 
	    if (keyword !== '') { 
	    	var allgs =[];
	        $('table tr:not(:first-child)').each(function() {
	            var cellText = $(this).find('td[name=gn]').text(); 
	            if (cellText.indexOf($.trim(keyword)) === -1) {
	                $(this).hide(); // 隐藏不包含关键字的表格行
	            }else{ 
	            	 var cellText1 = $(this).find('td[name=cp]').text(); 
	            	 allgs = $.merge(allgs, cellText1.split(",")); 
	            }
	        });
	        $('#div2').html(""); 
	        loadLT(allgs);
	    }
	}
	$("#bt3").click(function(){
		 $('table tr').each(function() {
			 $(this).show();
	      }); 
	});
	$("#bt1_5").click(function(){
		
		tasortchengji();
		
	});
	function tasortchengji(){
		var tdElements = $('table tr td[name=huanshoulv]');  
		var rowsArray = $('table tbody tr').toArray();

		  rowsArray.sort(function(a, b) {
		    var aValue = parseFloat($(a).find('td[name=huanshoulv]').text());
		    var bValue = parseFloat($(b).find('td[name=huanshoulv]').text()); 
		    return bValue - aValue;
		  });

		  var tableBody = $('table tbody');
		  tableBody.empty(); 
		  $.each(rowsArray, function(index, row) {
		    tableBody.append(row);
		  });
	}
	
	$("#bt0").click(function(){
		load(); 
	});
	//load();
})();
  
</script>

</body>
</html>